package com.gvfish.backingbean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;

import com.gvfish.entity.Article;
import com.gvfish.entity.Category;
import com.gvfish.service.ArticleManager;
import com.gvfish.service.CategoryManager;

@ManagedBean
@RequestScoped
public class ArticleShow {

	ApplicationContext ctx = FacesContextUtils
	.getWebApplicationContext(FacesContext.getCurrentInstance());
ArticleManager articleManager = (ArticleManager) ctx
	.getBean("articleManager");
CategoryManager categoryManager = (CategoryManager) ctx.getBean("categoryManager");
private Long id;
private Long categoryId;
private Article article;
private Category category;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setArticle(Article article) {
		this.article = article;
	}

	public Article getArticle() {
		if (article==null&&id != null) {
			article = articleManager.find(categoryId, id);
		}
		return article;
	}

	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}

	public Long getCategoryId() {
		return categoryId;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Category getCategory() {
		if(category==null){
			category = categoryManager.find(categoryId);
		}
		return category;
	}

}
